<?php
namespace Admin\Controller;
use Admin\Controller\AdminController;
class ConfigController extends AdminController {
	public function index(){
		$arr=M('Config')->select();
		foreach ($arr as $k=>$v){
			$config[$v['key']][0]=$v['value'];
		}
		$this -> assign('config',$config);
		$this ->display();
	}
	public function add(){
		$key = I('key');
		$vlaue = I('value');
		if(empty($key)){
			$this -> error('key值不能为空');
		}
		if(empty($vlaue)){
			$this -> error('value值不能为空');
		}
		$data['key'] = $key;
		$data['value'] = $vlaue;
		if(!M('Config')->data($data)->add()){
			$this -> error('配置项增加失败');
		}
		$this -> success('配置项增加成功');
	}
	public function edit(){
		$configkey = M('Config')->field('key')->select();
		foreach($configkey as $k=>$v){
			$data[$v['key']] = I($v['key']);
		}
		foreach($data as $kk=>$vv){
			$re[] = M('Config')->where(array('key' => $kk))->setField('value',$vv);
			//$re[] = M('Config')->where(C("DB_PREFIX")."config.key='$kk'")->setField('value',$vv);
		}
		if(!re){
			$this -> error('修改失败');
		}
		$this -> success('修改成功');
	}
}